package com.tjp.eight.ui.fragment.bindingphone;

import com.tjp.eight.AllRetrofit;
import com.tjp.eight.ResultModel;
import com.tjp.eight.base.BasePresenterImpl;
import com.tjp.eight.constant.UrlConstant;
import com.tjp.eight.net.NetCallBack;
import com.tjp.eight.net.SubscribeCallBack;
import com.tjp.eight.utils.AppUtils;

import okhttp3.RequestBody;

/**
 * Created by Administrator on 2017/3/23.
 */
public class BindingPhonePresenter extends BasePresenterImpl<BindingPhoneView> {
    private BindingPhoneService service = AllRetrofit.getRetrofit(UrlConstant.BaseUrl).create(BindingPhoneService.class);

    public BindingPhonePresenter(BindingPhoneView phoneView) {
        attachView(phoneView);
    }

    public void bindingphonecode(String codePJson) {
        RequestBody body = AppUtils.getRequestBody(codePJson);
        addSubscription(service.bindingphonecode(body), new SubscribeCallBack<>(new NetCallBack<ResultModel>() {
            @Override
            public void onSuccess(ResultModel model) {
                view.getCodeSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {

            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    public void submit(String bindingPhonePJson) {
        RequestBody body = AppUtils.getRequestBody(bindingPhonePJson);
        addSubscription(service.submit(body), new SubscribeCallBack<>(new NetCallBack<ResultModel>() {
            @Override
            public void onSuccess(ResultModel model) {
                view.subSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {

            }

            @Override
            public void onCompleted() {

            }
        }));
    }
}
